﻿using System;
using System.Text;
using System.Net.Sockets;
using System.Threading;
using System.Runtime.Serialization.Formatters.Binary;
using System.Diagnostics;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using RedCorona.Net;
using Silmoon;
using Levi.Finance.Server.Common;

namespace Levi.Finance.Server
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			Startup startup = new Startup();
			startup.Start();
			while (startup.f.RunningState == Silmoon.MySilmoon.RunningState.Running) {
				string input = Console.ReadLine ();
				switch (input) {
				case "exit":
					startup.Stop ();
					break;
				default:
					startup.f.onInputText (input);
					break;
				}
			}
		}
	}

	public class Startup
	{
		public ABC f;

		public Startup ()
		{
			f = new ABC ();
			f.OnOutputTextMessage += new Silmoon.MySilmoon.OutputTextMessageHandler (f_OnOutputTextMessage);
			//f.Start();
		}

		public Startup (bool nooutput)
		{
			f = new ABC ();
			if (nooutput)
				f.OnOutputTextMessage += new Silmoon.MySilmoon.OutputTextMessageHandler (f_OnOutputTextMessage);
		}

		void f_OnOutputTextMessage (string message, int flag)
		{
			if (flag == -1)
				Console.ForegroundColor = ConsoleColor.Red;
			if (flag == 1)
				Console.ForegroundColor = ConsoleColor.Green;
			Console.WriteLine (message);
			Console.ResetColor ();
		}

		public void Start ()
		{			
			f.Start ();
		}

		public void Stop ()
		{
			f.Stop ();
		}
	}
}

